package com.rongzhe.house.presenter;

import android.content.Intent;
import android.os.Handler;

import com.rongzhe.house.entity.Dictionary;
import com.rongzhe.house.internet.DataListener;
import com.rongzhe.house.manager.ConfigManager;
import com.rongzhe.house.manager.DictionaryManager;
import com.rongzhe.house.manager.TagManager;
import com.rongzhe.house.manager.UserManager;
import com.rongzhe.house.ui.UiControlInterface;
import com.rongzhe.house.ui.activity.LoginActivity;
import com.rongzhe.house.ui.activity.MainActivity;

import java.util.List;

/**
 * Created by huang on 2017/12/18.
 */

public class WelcomPresenter extends BasePresenter {

    public WelcomPresenter(UiControlInterface uiControlInterface) {
        super(uiControlInterface);
    }

    private Handler mHandler = new Handler();

    @Override
    public void start(Intent intent) {
        if (UserManager.getInstance().isLogin()) {
            UserManager.getInstance().getUserInfo(null);
        }
        ConfigManager.getInstance().loadSystemConfig();
        DictionaryManager.getInstance().getAllDictionary(new DataListener<List<Dictionary>>() {
            @Override
            public void onSuccess(List<Dictionary> data, String message) {
            }

            @Override
            public void onFailed(Throwable error, String message) {
                getUiControlInterface().showToast(message);
            }

            @Override
            public void onEnd() {

            }
        });
        TagManager.getInstance().getAllTags(null);
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(mContext, MainActivity.class);
                getUiControlInterface().launchActivity(false, intent);
                getUiControlInterface().finish();
            }
        }, 3000);
    }
}
